<?php

namespace app\index\dao;

use app\common\model\Help;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use think\Collection;

/**
 * HelpDao 数据访问对象
 * Class HelpDao
 * @package app\dao
 * @method Help findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method Help insertActive(array $params, array $allow_field = [])
 * @method Help updateActive(Help $model, array $params, array $allow_field = [])
 * @method Help findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method Help updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(Help $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class HelpDao
{
    use DaoTrait;

    /**
     * @var Help
     */
    private $baseModel;

    /**
     * HelpDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = Help::class;
    }

    public function select(array $categoryIds, $page, $page_size): Collection
    {
        return Help::when(!empty($categoryIds), fn($query) => $query->whereIn('categoryId', $categoryIds))
            ->field(true)
            ->append(['plainContent'])
            ->hidden(['content'])
            ->order('id', 'DESC')
            ->paging($page, $page_size)
            ->select();
    }
}
